import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// 自动引入api
import AutoImport from 'unplugin-auto-import/vite'
import { AntDesignVueResolver} from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      include: [/\.[tj]sx?$/, /\.vue$/, /\.vue\?vue/, /\.md$/],
      imports: [
        // 插件预设支持导入的api
        'vue',
        'vue-router',
        'pinia',
        // custom
        {
          axios: [
            // default imports
            ['default', 'axios'], // import { default as axios } from 'axios',
          ],
          lodash: [
            ['default', '_'],
          ],
          echarts: [
            ['*', 'echarts'],
          ],
          '@/api/index.js': [
            ['default', 'api'],
          ],
          '@/api-ws/index.js': [
            ['default', 'apiWs'],
          ],
          '@/store/index.js': [
            ['default', 'piniaStore'],
          ],
          'ant-design-vue': [
            ['*', 'andv'],
          ],
        },
      ],
    }),
    Components({
      dirs: ['src/components'], // 配置需要默认导入的自定义组件文件夹，该文件夹下的所有组件都会自动 import
      resolvers: [
        AntDesignVueResolver({ importStyle: false, resolveIcons: true }),
      ],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
})
